package org.example.mall.Pojo;


import lombok.Data;

import java.util.Collections;
import java.util.List;

@Data
public class ProductInfo {
    private Products Preview;
    private List<ProductConfigItem> Config = new java.util.ArrayList<>(Collections.emptyList());;

    public void setPPreview(Products p) {
        this.Preview = p;
    }

    public void setPConfig(List<List<ProductsConfig>> pCLL) {
        for(List<ProductsConfig> pCL : pCLL) {
            if(pCL.isEmpty()) {continue;}
            this.Config.add(new ProductConfigItem(pCL.get(0).getItemTitle(), pCL));
        }
    }

    public ProductInfo(Products p, List<List<ProductsConfig>> pCLL) {
        setPPreview(p);
        setPConfig(pCLL);
    }
}
@Data
class ProductConfigItem {
    private String itemTitle;
    private List<ProductConfigItemRow> itemRow = new java.util.ArrayList<>(Collections.emptyList());

    public void setItemTitle(String iTitle) {
        this.itemTitle = iTitle;
    }

    public void setItemRow(List<ProductsConfig> pCL) {
        for(ProductsConfig pC: pCL) {
//            if(this.itemTitle != pC.getItemTitle()) {continue;}
            this.itemRow.add(new ProductConfigItemRow(pC.getItem(), pC.getValue()));
        }
    }

    public ProductConfigItem(String iTitle, List<ProductsConfig> iRow) {
        setItemTitle(iTitle);
        setItemRow(iRow);
    }
}
@Data
class ProductConfigItemRow {
    private String item;
    private String value;

    public ProductConfigItemRow(String item_name, String item_value) {
        this.item = item_name;
        this.value = item_value;
    }
}